package cn.kiliter.web.servlet;

import cn.kiliter.model.Product;
import cn.kiliter.serviece.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productInfo")
public class productInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String idstr = request.getParameter("id");
        int id=0;
        if(idstr!=null&&!"".equals(idstr)){
            id=Integer.parseInt(idstr);
        }
        ProductService service=new ProductService();
        Product product=service.findProDuctById(id);
        if(product!=null) {
            request.setAttribute("pr", product);
        }
        request.getRequestDispatcher("/product_info.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
